"""
@name: 11、网段存活检测
@author: liangrui
@projectname: pythonProject
"""
from  multiprocessing import Pool

def task(i):
    res = ping(f'192.168.2.{i}')
    if res.success() == True:
        print(f'存活ip为: 192.168.2.{i}')

if __name__ == "__main__":
    p = Pool(processes=20,maxtasksperchild=10)#创建一个进程池，建议和cpu核数一致
    for  i in range(255):
        p.apply_async(func = task,args=(i,))
     #关闭进程池，不接受任务了
    p.close()
    # 等待子进程执行完毕在执行父进程
    p.join()

